package com.example.smartcity_poverty.ui.AllService.SmartTrafficControl

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import com.example.smartcity_poverty.App.Companion.getToken
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.Repository.api
import com.example.smartcity_poverty.logic.Repository.coroutine
import com.example.smartcity_poverty.logic.util.Util.show
import kotlinx.coroutines.Dispatchers

class SmartTcActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_smart_tc)
        title = "智慧交管"

        // 测试发起网络请求
        coroutine(Dispatchers.Main) {
            if (getToken().isNotEmpty()) {
                api.getStcDataAll(getToken(), "辽B12345").apply {
                    if (this.code == 200) {
                        runOnUiThread {
                            this.msg?.show()
                            "${this.rows?.size}".show()
                        }
                    } else runOnUiThread { this.msg?.show() }
                }
            } else runOnUiThread { "请先登录！".show() }
        }

    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}